import React, { Fragment, useState, useEffect } from 'react'
import Taro from '@tarojs/taro'
import { AtSwipeAction } from "taro-ui"
import { View, Text, ScrollView, Image, Radio } from '@tarojs/components'
import './index.scss'

import store from '../../store'

export default function MyShopCart ({ myCartNum }) {
  // 前往商品分类页面
  function goToification () {
    Taro.switchTab({
      url: '../../pages/ification/index'
    })
  }
  const [MycartComList, useMyCartComList] = useState(store.getState().cartComList)
  useEffect(() => {
    // store.subscribe(storeChange)
  }, [])

  return (
    <Fragment>
      {

        MycartComList.length > 0 ? (

          <ScrollView
            scrollY
            className='shop_cart_list'>
            {
              MycartComList.map((item, index) => {
                return (
                  <View className='shop_cart_item' key={index}>
                    {/* 单选框 */}
                     <Image className='cart_item_img' src={item.commUrl}></Image>
                    <View className='cart_item_fr'>
                      <Text className='cart_fr_tit'>{item.tit}</Text>
                      <Text className='cart_fr_con'>{item.description}</Text>
                      <View className='cart_fr_boo'>
                        <Text className='new_price'>{item.newPrice}</Text>
                        <Text className='old_price'>{item.oldPrice}</Text>
                        {/*<View className='calculation'>*/}
                        {/*  <Text className='less'  >-</Text>*/}
                        {/*  <Text className='num'>{item.num}</Text>*/}
                        {/*  <Text className='add'  >+</Text>*/}
                        {/*</View>*/}
                        <View className='comm_de_fr'>
                          <Text className={['reduce_comm_btn', item.showMoveTag? 'move_tag':'no_move_tag']} onClick={(e) => reduceNum(e,index)}>-</Text>
                          <Text className={item.showMoveTag? 'move_tag':'no_move_tag'}>{item.commNum}</Text>
                          <Text className='add_comm_btn' onClick={(e) => addCommBtn(e,index)}>+</Text>
                        </View>
                      </View>
                    </View>
                  </View>
                )
              })
            }

          </ScrollView>
        ) : (
            <View className="my_shop_cart">
              <View className="cart_null">
                <Text className='cart_one'>购物车竟然是空的</Text>
                <Text className='cart_tow'>再忙，也要记得买点东西犒劳自己~</Text>
                <Text className='cart_treen' onClick={() => goToification()}>去逛逛</Text>
              </View>
            </View>
          )
      }


    </Fragment>

  )
}
